<?php
if (isset($_GET['cd']) &&  !empty($_GET['cd']) ){
    include '../c/config.php';
    $code=$_GET['cd'];
    $url='https://api.weixin.qq.com/sns/jscode2session?appid='.$appId.'&secret='.$secret.'&js_code='.$code.'&grant_type=authorization_code';
    $getData=json_decode(file_get_contents($url));
    $openid=$getData->openid;
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    if (!$mysqli->set_charset("utf8")) {
       
    }
    $query=$mysqli->query("SELECT id FROM users where openid='".$openid."' limit 0,1 ");
    if($query->num_rows>0){
    }else{
        $mysqli->query("insert into users(openid,createtime) values('".$openid."','".date("Y-m-d H:i:s")."')  ");
    }
    $mysqli->close();
    echo json_encode(array('o'=>$openid));
}

